package com.study.d3_method_reference;
import java.util.Arrays;
public class Test2 {
    public static void main(String[] args) {
        //理解实例方法的引用
        Student[] students = new Student[4];
        students[0]=new Student("一帆风顺",175,'男',20);
        students[1]=new Student("二话不说",165,'男',130);
        students[2]=new Student("三心二意",170,'女',220);
        students[3]=new Student("四面八方",185,'女',10);
        Test2 t2 = new Test2();
//      1、  Arrays.sort(students, (o1, o2)-> o2.getAge()-o1.getAge());
//      2、  Arrays.sort(students, (o1, o2)-> t2.compare(o1,o2));
        //实例方法的引用
        //使用场景：如果某个lambda表达式里只是调用一个实例方法，并且前后参数的形式一致，就可以使用实例方法引用
        Arrays.sort(students, t2::compare);//3
        System.out.println(Arrays.toString(students));
    }
    public int compare(Student o1,Student o2){
        return o2.getAge()-o1.getAge();
    }
}
